<?php

namespace App\Console\Commands;

use App\Jobs\Viewer;
use App\Models\Position;
use App\Services\CrawlerService\CrawlerService;
use App\Services\CrawlerService\driver\Xinxin21ccnnDriver;
use App\Services\TagService\TagService;
use Illuminate\Console\Command;

class Tagged extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'make_tag {ext?}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $ext = $this->argument('ext');
        if ($ext == 'refresh') {
            $positions = Position::get();
        } else {
            $positions = Position::whereDoesntHave('tags')->get();
        }
        $tag_service = new TagService();
        $bar=$this->output->createProgressBar(count($positions));
        foreach ($positions as $position) {
            $bar->advance();
            $tag_service->position($position);
        }
        $bar->finish();
        $this->info('更新完成');
    }
}
